home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 7.4 KB | 215 lines | [TEXT/GEOL] |
- Item 9869936 25-Oct-90 05:36PDT
-
- From: POWERUP.ENG Power Up Software,PRT
-
- To: MACAPP.TECH$ MacApp Technical
-
- Sub: Validate on mouseDown
-
- Attn: MacApp.Tech$
- SentBy: James Plamondon
- Date 10/24/90
- Subject Validate on mouseDown
- From James Plamondon
- To MacApp.Tech$
-
- Subject: Validate on mouseDown
- Gentlepersons,
-
- I've modified MacApp so that it validates the current edit text item when
- another control is clicked. If you're interested in this behaviour (MacApp's,
- not mine), read on.
-
- When the user begins typing in a TEditText view, the TDialogView displays a
- TTEView that overlies the TEditText view. The TTEView handles the editing.
-
- When the user shifts her attention away from the text being edited, though,
- and instead focuses her attention of some control by clicking on it, the darn
- text is still sitting there, unvalidated. The user may spend the next five
- minutes manipulating buttons, popups, lists, etc., before finally dismissing
- the dialog — at which point the text is, at last, validated. By now the user
- has completely forgotten what item he has edited, where it was on the dialog,
- what he entered that turned out to be invalid, why he wanted to edit it in the
- first place, and so on (possibly even what sex she was before the validation,
- if his change of assumed gender in mid-paragraph is any indication).
-
- I think that this is less than ideal.
-
- Consider the type-in popup, described on pages 3 & 4 of Human Interface Note
- #9 (October 1990). It allows the user to enter a value into an edit text
- item, or to select a value from an associated popup menu. If the value
- entered in the edit text item does not match a value in the popup, the value
- in the edit text item must be added to the popup's menu.
-
- Before you can add the edit text item's value to the popup's menu, though,
- you've got to validate it. This can be done by overriding the popup control's
- DoMouseCommand() method as follows:
-
- {——————————————————————————————————————————————}
-
- TMyPopup.DoMouseCommand(VAR theMouse: Point;
- VAR info: EventInfo;
- VAR hysteresis: Point): TCommand; OVERRIDE;
- VAR
- theDialog: TDialogView;
-
- BEGIN
- theDialog := TDialogView(GetDialog);
-
- IF (theDialog <> NIL) &
- (theDialog.fCurrentEditText = fEditText) &
- (fEditText.Validate <> kValidValue) { Validate() adds a menu
- entry if needed }
- THEN DoMouseCommand := NIL
- ELSE DoMouseCommand := INHERITED DoMouseCommand(<…>);
- END; { DoMouseCommand }
-
- {——————————————————————————————————————————————}
-
- However, this does not solve the problem in general, but rather in this
- specific instance only. I propose a more general solution, which requires
- changing MacApp.
-
- First, add the following routine to TView:
-
- {——————————————————————————————————————————————}
-
- FUNCTION TView.ShiftAttentionTo(theView: TView): BOOLEAN;
- { Returns TRUE if SELF can shift its attention to the given view. The default
- does
- nothing, and returns TRUE. It is overridden in TDialogView (qv) to return
- TRUE
- if the current edit text item is successfully deselected. }
- BEGIN
- ShiftAttentionTo := TRUE;
- END; { ShiftAttentionTo }
-
- {——————————————————————————————————————————————}
-
- Then, modify TView.HandleMouseDown as follows:
-
- {——————————————————————————————————————————————}
-
- FUNCTION TView.HandleMouseDown(theMouse: VPoint;
- VAR info: EventInfo;
- VAR hysteresis: Point;
- VAR theCommand: TCommand): BOOLEAN;
-
- VAR
- viewThatHandledMouse: TView;
- theQDMouse: Point;
- {$IFC qValidateOnMousedown}
- theDialogView: TView; { TDialogView is not defined in UMacApp
- }
- {$ENDC qValidateOnMousedown}
-
- FUNCTION TestMouse(theSubView: TView): BOOLEAN;
-
- VAR
- subViewPt: VPoint;
-
- BEGIN
- subViewPt := theMouse;
- theSubView.SuperToLocal(subViewPt);
- IF theSubView.ContainsMouse(subViewPt) THEN
- TestMouse := theSubView.HandleMouseDown(subViewPt, info,
- hysteresis, theCommand)
- ELSE
- TestMouse := FALSE;
- END;
-
- BEGIN
- HandleMouseDown := FALSE;
- theCommand := NIL;
-
- {Assume if we got here then we already know the mouse is in this view}
-
- viewThatHandledMouse := LastSubViewThat(TestMouse);
-
- {$IFC qValidateOnMousedown}
- IF viewThatHandledMouse <> NIL
- THEN {a subview handled it}
- HandleMouseDown := TRUE
- ELSE
- BEGIN {see if we can handle it}
- theDialogView := GetDialogView;
-
- IF IsViewEnabled &
- ((theDialogView = NIL) | theDialogView.ShiftAttentionTo(SELF)) &
- Focus
- THEN {we CAN handle it!}
- BEGIN
- theQDMouse := ViewToQDPt(theMouse);
- theCommand := DoMouseCommand(theQDMouse, info, hysteresis);
- HandleMouseDown := TRUE;
- END; { then }
- END; { else }
- {$ELSEC qValidateOnMousedown}
- IF viewThatHandledMouse <> NIL THEN {a subview handled it}
- HandleMouseDown := TRUE
- ELSE IF IsViewEnabled & Focus THEN {see if we can handle
- it}
- BEGIN
- theQDMouse := ViewToQDPt(theMouse);
- theCommand := DoMouseCommand(theQDMouse, info, hysteresis);
- HandleMouseDown := TRUE;
- END;
- {$ENDC qValidateOnMousedown}
- END;
-
- {——————————————————————————————————————————————}
-
- Lastly, override TView.ShiftAttentionTo() (which we just added to TView) in
- TDialogView, as follows:
-
- {——————————————————————————————————————————————}
-
- FUNCTION TDialogView.ShiftAttentionTo(theView: TView): BOOLEAN; OVERRIDE;
- { Returns TRUE if the current edit text item is successfully deselected.
- This method is only called from TView.HandleMouseDown(). }
- VAR
- lastCommand: TCommand;
-
- BEGIN
- ShiftAttentionTo := TRUE; { default }
-
- IF (fCurrentEditText <> NIL) & { we're editing }
- (fTEView <> NIL) &
- (theView <> fCurrentEditText) & { but the mouseDown isn't in the edited
- view }
- (theView <> fTEView) &
- Member(theView, TControl) { and the new view is a control }
- THEN
- BEGIN
- { Commit the last command to prevent undo from applying to the wrong
- edit text, and to ensure that all changes are made before
- validating. }
- lastCommand := fTEView.GetLastCommand;
-
- IF (lastCommand <> NIL) &
- (lastCommand.fView = fTEView)
- THEN
- fTEView.CommitLastCommand;
-
- ShiftAttentionTo := (fCurrentEditText.Validate = kValidValue);
- END; { then }
- END; { ShiftAttentionTo }
-
- {——————————————————————————————————————————————}
-
- These changes ensure that the current edit text item's text is validated
- whenever a mouseDown is directed at another control. I have found that these
- changes simplify a number of my dialogs, in which there is interaction between
- the value entered in the edit text item and the other controls in the dialog.
-
- I hope that these changes do not prove to be unstable, unwarranted, or
- misdirected — that's always rather embarassing. However, if you want to take
- this opportunity to embarass me, please don't hesitate to point out any flaws
- in, or possible improvements to, the code. I promise to take it well — and in
- any event, I will remain
-
- Yours,
-
- James Plamondon
-
-